package com.example.administrator.energyida.activity;

import android.app.Activity;
import android.graphics.Color;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.energyida.R;
import com.example.administrator.energyida.fragment.ByDayFragment;
import com.example.administrator.energyida.fragment.ByMonthFragment;
import com.jaeger.library.StatusBarUtil;

public class ManualAddActivity extends FragmentActivity {

    private TextView btnBack;
    private Button btnDay;
    private Button btnMonth;
    private Button btnCommit;

    private String wId;
    private Boolean byDay = false;
    private Boolean byMonth = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_manual_add);

        initView();

        btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        btnDay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickDay();

                getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout, new ByDayFragment()).commit();
            }
        });

        btnMonth.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickMonth();

                getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout, new ByMonthFragment()).commit();
            }
        });

        btnCommit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initView() {
        // 设置状态栏的颜色
        StatusBarUtil.setColor(ManualAddActivity.this, Color.parseColor("#10cafd"), 50);

        btnBack = findViewById(R.id.text_manualAdd_back);
        btnDay = findViewById(R.id.manualAdd_button_day);
        btnMonth = findViewById(R.id.manualAdd_button_month);
        btnCommit = findViewById(R.id.manualAdd_button_commit);

        clickDay();

        wId = getIntent().getStringExtra("wId");
    }

    public void saveEditData(int position, String str) {
        Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
    }

    //点击按天输入
    private void clickDay() {
        if (byDay) {
            return;
        }
        byDay = true;
        byMonth = false;
        btnDay.setBackgroundResource(R.color.colorAccent);
        btnDay.setTextColor(Color.parseColor("#ffffff"));
        btnMonth.setBackgroundResource(R.color.color_bg_grey);
        btnMonth.setTextColor(Color.parseColor("#000000"));
    }

    //点击按月输入
    private void clickMonth() {
        if (byMonth) {
            return;
        }
        byDay = false;
        byMonth = true;
        btnDay.setBackgroundResource(R.color.color_bg_grey);
        btnDay.setTextColor(Color.parseColor("#000000"));
        btnMonth.setBackgroundResource(R.color.colorAccent);
        btnMonth.setTextColor(Color.parseColor("#ffffff"));
    }

    @Override
    protected void onResume() {
        super.onResume();
        btnDay.performClick();
    }
}
